package com.win.controller.flume;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;

import java.io.IOException;
import java.io.InputStream;

public class AutoCloseableChannelSftp implements AutoCloseable {

    private final ChannelSftp sftpChannel;

    public AutoCloseableChannelSftp(Session session) throws JSchException {
        this.sftpChannel = (ChannelSftp) session.openChannel("sftp");
        this.sftpChannel.connect();
    }

    public void put(InputStream inputStream, String remoteFilePath) throws SftpException {
        sftpChannel.put(inputStream, remoteFilePath);
    }

    @Override
    public void close() throws IOException {
        if (sftpChannel.isConnected()) {
            sftpChannel.disconnect();
        }
    }

    // 可能还需要实现其他ChannelSftp的方法...
}
